# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>
# Contributor: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=imageio
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.37.0
pkgrel=1
pkgdesc="Python library for reading and writing a wide range of image, video, scientific, and volumetric data formats (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/imageio/imageio'
msys2_references=(
  'aur: python-imageio'
  'gentoo: dev-python/imageio'
  'purl: pkg:pypi/imageio'
)
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-pillow")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
optdepends=("${MINGW_PACKAGE_PREFIX}-freeimage: for FreeImage backend"
            "${MINGW_PACKAGE_PREFIX}-opencv: for OpenCV backend"
            "${MINGW_PACKAGE_PREFIX}-python-tifffile: for working with TIFF files")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('71b57b3669666272c818497aebba2b4c5f20d5b37c81720e5e1a56d59c492996')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/python -m pytest
}

package() {
  cd "${srcdir}"/python-build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  # Remove utilities for downloading binary dependencies
  rm -rf "$pkgdir${MINGW_PREFIX}"/bin
}
